#include "shuangpin.h"
#include <stdio.h>


std::string translate_pyinput(const std::string &s)
{
    std::string ret;
    for(auto c : s)
    {
        if(c == '\b')
        {
            ret += "\\b";
        } 
        else
        {  
            ret.push_back(c);
        }
    }
    return ret;
}

int main(int argc, char *argv[])
{
    if(argc < 3)
    {
        printf("Usage:"
               "\t$test <ini_file> <input_str1> [input_str2] [input_str3]...\n");
        return -1;
    }

    printf("混合模式测试(全拼优先):\n");
    cpis::keyflow::CShuangPin sp1; 
    sp1.Init(cpis::keyflow::LoadSogouShuangPinMapByFilePath(argv[1])); //支持双拼
    std::string sp;
    for(int i=2; i<argc; i++)
    {
        sp = argv[i];
        if(sp == "CLEAR")
        {
            printf("Calling Clear\n");
            sp1.Clear();
        }
        else
        {
            sp1.Decode(sp);
            printf("input:%s, fullpy:%s, py:%s, comp:%s\n", argv[i], sp1.GetFullPinYin().c_str(), translate_pyinput(sp1.GetLastPinYin()).c_str(), translate_pyinput(sp1.GetComposition()).c_str());
        }
    }
 
    printf("纯双拼模式测试:\n");
    cpis::keyflow::CShuangPin sp2; 
    sp2.Init(cpis::keyflow::LoadSogouShuangPinMapByFilePath(argv[1]), false); //纯双拼
    for(int i=2; i<argc; i++)
    {
        sp = argv[i];
        if(sp == "CLEAR")
        {
            printf("Calling Clear\n");
            sp2.Clear();
        }
        else
        {
            sp2.Decode(sp);
            printf("input:%s, fullpy:%s, py:%s, compositon:%s\n", argv[i], sp2.GetFullPinYin().c_str(), translate_pyinput(sp2.GetLastPinYin()).c_str(), translate_pyinput(sp2.GetComposition()).c_str());
        }
    }
   
    return 0;
}

